package com.chenjj.java.thread.oom;

/**
 * 模拟Unable to create new native thread
 */
public class ThreadOOM {
    public static void main(String[] args) throws InterruptedException {
        int threadNum = Integer.parseInt(args[0]);
        int i = 0;
        if (threadNum > 0){
            while (i < threadNum){
                new Thread(new Runner()).start();
                i++;
            }
            while (true){
                Thread.sleep(5000);
                System.out.println("Thread start " + threadNum + " finished...");
            }
        }else{
            while (true){
                Thread.sleep(1000);
            }
        }
    }

    static class Runner implements Runnable{

        @Override
        public void run() {
            while (true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
